<%@ page language="java"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<html>
<head> <title>View presentations</title>
</head>
<body>
<center>
<p><font color="#0080FF" size="25">View Presentations</font></p>
<%
       try
       {
		if(session.getAttribute("logged_in") == "true")
		{
			
			if(session.getAttribute("user_level") == "administrator")
			{
				

				
				String DRIVER = "com.mysql.jdbc.Driver";
				Class.forName(DRIVER);
				Connection con=null;
				ResultSet rst=null;


				String url="jdbc:mysql://ecstiger.cs.andrews.edu/d562_2010_01?user=u562_2010_01&password=YPJ8f4We";
				con=DriverManager.getConnection(url);

				PreparedStatement stmt = con.prepareStatement("SELECT * FROM presentation;");
				rst = stmt.executeQuery();

		out.println("<TABLE border=1><tr><th>Id</th><th>Allowed</th><th>File Name</th><th>User Id</th><th></th></tr>");
				

				while(rst.next())
				{
					out.println("<tr><th>" + rst.getInt(1) + "</th><th>" + rst.getInt(2) + "</th><th>" + rst.getString(3) + "</th><th>" + rst.getString(4) + "</th><th><form method=POST action=view_presentation_select.jsp><input type=hidden name=id value=" + rst.getInt(1) + "><input type=SUBMIT value=Select></form></th></tr>");	
				}
				out.println("</TABLE>");

				rst.close();
				stmt.close();
				con.close();

			}
			else
			{
				
				
				String DRIVER = "com.mysql.jdbc.Driver";
				Class.forName(DRIVER);
				Connection con=null;
				ResultSet rst=null;


				String url="jdbc:mysql://ecstiger.cs.andrews.edu/d562_2010_01?user=u562_2010_01&password=YPJ8f4We";
				con=DriverManager.getConnection(url);

				PreparedStatement stmt = con.prepareStatement("SELECT * FROM presentation WHERE user_id = '" + session.getAttribute("id") + "';");
				rst = stmt.executeQuery();
		
				out.println("<TABLE border=1><tr><th>Id</th><th>Allowed</th><th>File Name</th><th>User Id</th><th></th></tr>");

				while(rst.next())
				{
					out.println("<tr><th>" + rst.getInt(1) + "</th><th>" + rst.getInt(2) + "</th><th>" + rst.getString(3) + "</th><th>" + rst.getString(4) + "</th><th><form method=POST action=view_presentation_select.jsp><input type=hidden name=id value=" + request.getParameter("id") + "><input type=SUBMIT value=Select></form></th></tr>");	
				}
				out.println("</TABLE>");

				rst.close();
				stmt.close();
				con.close();
			}
		}
		else
		{
			out.println("Not Logged In");
		}
       }
       catch(Exception e)
       {
           out.println(e);
       }	
%>
<br>
<a href="menu.jsp">Main Menu</a>
</center>
</body>
</table>
</center>
</div>
</body>
</html>

